<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>

<body>
    <div id="app"></div>
</body>
<script>
    // 针对数组的功能
    const listEffect = () => {
        const { reactive } = Vue
        const list = reactive([])
        const addItem = (item) => {
            list.push(item)
        }
        return { list, addItem }
    }
    //针对input框的功能
    const inputEffect = () => {
        const { ref } = Vue
        const iptValue = ref('')
        const handlerInputValue = (e) => {
            iptValue.value = e.target.value
        }
        return { iptValue, handlerInputValue }
    }
    const vm = {
        template: `
                    <div>
                        <input type="text" 
                            :value="iptValue"
                            @input="handlerInputValue"
                        />
                        {{iptValue}}
                        <button @click="addItem(iptValue)">点击</button>
                        <ul>
                            <li v-for="item in list">
                                {{item}}
                            </li>
                        </ul>
                    </div>
                `,
        setup () {
            const { iptValue, handlerInputValue } = inputEffect()
            const { list, addItem } = listEffect()
            return { iptValue, list, handlerInputValue, addItem }
        }
    }
    const app = Vue.createApp(vm)
    app.mount('#app')
</script>

</html>